/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2025-02-10 10:34:23
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2025-02-25 10:04:41
 * @FilePath: /vue3-admin-server/src/app.module.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

// src/app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { WinstonModule } from 'nest-winston';
import * as winston from 'winston';
import * as DailyRotateFile from 'winston-daily-rotate-file';
import { ConfigModule } from '@nestjs/config';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { V1Module } from './admin/v1/v1.module';
import { UserEntity } from './entities/user.entity';
import { RoleEntity } from './entities/role.entity';
import { MenuEntity } from './entities/menu.entity';
import { DeptEntity } from './entities/dept.entity';
import { FileEntity } from 'src/entities/file.entity';

@Module({
    imports: [
        ConfigModule.forRoot({
            isGlobal: true
        }),
        WinstonModule.forRoot({
            transports: [
                new winston.transports.Console({
                    format: winston.format.combine(
                        winston.format.timestamp(),
                        winston.format.ms(),
                        winston.format.colorize(),
                        winston.format.simple()
                    )
                }),
                new DailyRotateFile({
                    filename: 'logs/app-%DATE%.log',
                    datePattern: 'YYYY-MM-DD',
                    zippedArchive: true,
                    maxFiles: '14d'
                })
            ]
        }), // 添加: 引入 LoggerModule
        TypeOrmModule.forRoot({
            type: 'mysql',
            host: process.env.DB_HOST ?? 'localhost',
            port: process.env.DB_PORT ?? 3306,
            username: process.env.DB_USERNAME,
            password: process.env.DB_PASSWORD,
            database: process.env.DB_DATABASE,
            entities: [
                UserEntity,
                RoleEntity,
                MenuEntity,
                DeptEntity,
                FileEntity
            ], // 注册实体
            autoLoadEntities: true // 自动加载实体
            // synchronize: process.env.NODE_ENV === 'development' ? true : false // 开发环境建议开启，生产环境建议关闭
        }),
        V1Module
    ],
    controllers: [AppController],
    providers: [AppService]
})
export class AppModule {
    /***/
}
